<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>民工信息修改</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../js/formSelects/formSelects-v4.css" media="all">
    <link rel="stylesheet" href="../css/font/iconfont.css" media="all">

    <style>
        .other_name {
            display: inline-block;
            margin-right: 10px;
            cursor: pointer;
        }
        .other_name>i {
            margin-left: 5px;
        }
        .other_name>i:hover {
            color: #FFFFFF;
        }

        .layui-form-label{
            width:140px;
        }
        .layui-input-block{
            margin-left: 170px;
        }
        a{
            color:#fff;
        }
        a:hover {
            color: #00c0ef;
        }
    </style>
</head>
<body>


<div style="margin-top: 40px; margin-right: 30px;">
    <form class="layui-form" action=""  lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>民工姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name"  lay-verify="required" readonly placeholder="民工姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>性别</label>
            <div class="layui-input-block">
                <select name="sex"  id="sex" lay-verify="required"   lay-search="">
                    <option value="" selected="selected">请选择</option>
                    <option value="0">男</option>
                    <option value="1">女</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" id="phone"  lay-verify="required|phone" placeholder="联系电话" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>身份证号</label>
            <div class="layui-input-block">
                <input type="text" name="number"  id="number" lay-verify="required|identity" placeholder="身份证号" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span>籍贯</label>
            <div class="layui-input-block">
                <input type="text" name="adress"  id="adress" lay-verify="required" placeholder="籍贯" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="divSubmit">
            <div class="layui-input-block"  style="text-align: center;">
                <button id="btnSub" class="layui-btn" lay-filter="formSubmit"  lay-submit="">提交</button>
            </div>
        </div>

    </form>
</div>

</body>
<script src="../assets/layui/layui.js"></script>
<script src="../js/common.js"></script>
<script>
    layui.config({
        base: '../js/'
    }).extend({
        formSelects: 'formSelects/formSelects-v4'
    });
    var $;

    layui.use(['jquery','form','validate','common','element', 'laydate','upload','formSelects'], function () {
        var form = layui.form,
            layer = layui.layer,
            validate = layui.validate,
            formSelects = layui.formSelects,
            common = layui.common;
        $ = layui.jquery;

        validate.regVerify();

        var Id=common.getUrlParam("id");
        $.ajax({
            url: "../project/personInfo",
            dataType: "json",
            data: { Id: Id },
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    var data = rtn.data;
                    form.val('dataForm', {
                        name: data.name
                        , phone: data.phone
                        , number: data.number
                        , adress: data.adress
                    });
                    $("#sex").find("option").each(function(){
                        if($(this).val()==rtn.data.sex){
                            $(this).attr('selected', 'selected');
                        }
                    });
                    form.render('select');
                    formSelects.render();

                    form.render();
                }
            }
        });

        form.on('submit(formSubmit)', function (data) {
            var name = $("#name").val();
            var sex = $("#sex").find("option:selected").val();
            var phone = $("#phone").val();
            var number = $("#number").val();
            var adress = $("#adress").val();
            if(name==""||sex==""||phone==""||number==""||adress=="")
            {
                common.showError('必填项不能为空!');
                return false;
            }
            if(number.length!=18){
                common.showMsg("请输入正确的身份证号");
                return false;
            }
            data.field.name = name;
            data.field.sex = sex;
            data.field.phone = phone;
            data.field.number = number;
            data.field.adress= adress;
            data.field.id= Id;
            $.ajax({
                type: 'post',
                url: '../project/personEdit',
                data: {json: JSON.stringify(data.field)},
                success: function (rtn) {
                    if (rtn.code === 0) {  //数据保存成功
                        var msg = "保存成功!";
                        common.showInfo(msg, function () {
                            //刷新前页
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.document.getElementById('btnSearch').click();
                            parent.layer.close(index);
                        });
                    }
                    else {
                        common.showError(rtn.msg);
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    common.showError('保存错误');
                }
            });
            return false;
        });
    })
</script>
</html>